package com.changgou.system;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@SpringBootApplication
@EnableEurekaClient
public class GateWayApplication {
	public static void main(String[] args) {
		SpringApplication.run(GateWayApplication.class,args);
	}

	@Bean
	public KeyResolver ipKeyResolver(){///令牌解析的意思
		return new KeyResolver() {
			@Override
			public Mono<String> resolve(ServerWebExchange exchange) {
				//获取访问的ip
				String ip = exchange.getRequest().getRemoteAddress().getHostName();
				//限制该ip，如，不能在1秒内连续访问
				Mono<String> just = Mono.just(ip);
				return just;
			}
		};
	}
}
